package com.cj.framework.app;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.yuanduan.mplus.db.dao.DaoMaster;
import com.yuanduan.mplus.db.dao.DaoSession;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by cj on 2016/5/10.
 * Email:781806481@qq.com
 */
public class BaseApplication extends Application {
    private static Context mContext;
    private static OkHttpClient okHttpClient;
    private static Handler mHandler;
    private static DaoSession daoSession;
    private static DaoMaster daoMaster;

    @Override
    public void onCreate() {
        super.onCreate();
        mHandler=new Handler();
        mContext=getApplicationContext();
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(mContext));
        okHttpClient=new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10,TimeUnit.SECONDS)
                .readTimeout(10,TimeUnit.SECONDS)
                .build();
        DaoMaster.OpenHelper helper=new DaoMaster.DevOpenHelper(getApplicationContext(),"mplus.db");

        daoMaster=new DaoMaster(helper.getWritableDatabase());
        daoSession=daoMaster.newSession();
    }
    public static Context getContext(){
        return mContext;
    }

    public static Handler getHandler(){
        return mHandler;
    }

    public static OkHttpClient getOkHttpClient(){
        return okHttpClient;
    }

    public static DaoSession getDaoSession(){
        return daoSession;
    }

    public static DaoMaster getDaoMaster(){
        return daoMaster;
    }
}
